home *** CD-ROM | disk | FTP | other *** search
/ Programming Microsoft Visual Basic .NET / Programming Microsoft Visual Basic .NET (Microsoft Press)(X08-78517)(2002).bin / setup / vbnet / 26 web services / advancedwsclient / form1.vb < prev   
Encoding:
Text File  |  2002-03-19  |  20.6 KB  |  497 lines

  1. Imports System.Threading
  2. Imports System.Text.RegularExpressions
  3. Imports System.Net
  4. Imports System.Web.Services.Protocols
  5.  
  6. Public Class Form1
  7.     Inherits System.Windows.Forms.Form
  8.  
  9. #Region " Windows Form Designer generated code "
  10.  
  11.     Public Sub New()
  12.         MyBase.New()
  13.  
  14.         'This call is required by the Windows Form Designer.
  15.         InitializeComponent()
  16.  
  17.         'Add any initialization after the InitializeComponent() call
  18.  
  19.     End Sub
  20.  
  21.     'Form overrides dispose to clean up the component list.
  22.     Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
  23.         If disposing Then
  24.             If Not (components Is Nothing) Then
  25.                 components.Dispose()
  26.             End If
  27.         End If
  28.         MyBase.Dispose(disposing)
  29.     End Sub
  30.  
  31.     'Required by the Windows Form Designer
  32.     Private components As System.ComponentModel.IContainer
  33.  
  34.     'NOTE: The following procedure is required by the Windows Form Designer
  35.     'It can be modified using the Windows Form Designer.  
  36.     'Do not modify it using the code editor.
  37.     Friend WithEvents btnAbort As System.Windows.Forms.Button
  38.     Friend WithEvents btnTestSession As System.Windows.Forms.Button
  39.     Friend WithEvents btnAsyncCall As System.Windows.Forms.Button
  40.     Friend WithEvents btnTimeout As System.Windows.Forms.Button
  41.     Friend WithEvents btnAsyncMulti As System.Windows.Forms.Button
  42.     Friend WithEvents btnPermanentSession As System.Windows.Forms.Button
  43.     Friend WithEvents btnCaching As System.Windows.Forms.Button
  44.     Friend WithEvents btnException As System.Windows.Forms.Button
  45.     Friend WithEvents btnWindowsAuthentication As System.Windows.Forms.Button
  46.     Friend WithEvents btnSoapHeaders As System.Windows.Forms.Button
  47.     Friend WithEvents btnCustomAuthentication As System.Windows.Forms.Button
  48.     Friend WithEvents btnOneWay As System.Windows.Forms.Button
  49.     Friend WithEvents btnSoapExtensions As System.Windows.Forms.Button
  50.     Friend WithEvents lblMessage As System.Windows.Forms.Label
  51.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
  52.         Me.btnTestSession = New System.Windows.Forms.Button()
  53.         Me.btnAbort = New System.Windows.Forms.Button()
  54.         Me.lblMessage = New System.Windows.Forms.Label()
  55.         Me.btnAsyncCall = New System.Windows.Forms.Button()
  56.         Me.btnTimeout = New System.Windows.Forms.Button()
  57.         Me.btnAsyncMulti = New System.Windows.Forms.Button()
  58.         Me.btnPermanentSession = New System.Windows.Forms.Button()
  59.         Me.btnCaching = New System.Windows.Forms.Button()
  60.         Me.btnException = New System.Windows.Forms.Button()
  61.         Me.btnWindowsAuthentication = New System.Windows.Forms.Button()
  62.         Me.btnSoapHeaders = New System.Windows.Forms.Button()
  63.         Me.btnCustomAuthentication = New System.Windows.Forms.Button()
  64.         Me.btnOneWay = New System.Windows.Forms.Button()
  65.         Me.btnSoapExtensions = New System.Windows.Forms.Button()
  66.         Me.SuspendLayout()
  67.         '
  68.         'btnTestSession
  69.         '
  70.         Me.btnTestSession.Location = New System.Drawing.Point(16, 264)
  71.         Me.btnTestSession.Name = "btnTestSession"
  72.         Me.btnTestSession.Size = New System.Drawing.Size(120, 40)
  73.         Me.btnTestSession.TabIndex = 0
  74.         Me.btnTestSession.Text = "Test session state"
  75.         '
  76.         'btnAbort
  77.         '
  78.         Me.btnAbort.Location = New System.Drawing.Point(16, 72)
  79.         Me.btnAbort.Name = "btnAbort"
  80.         Me.btnAbort.Size = New System.Drawing.Size(120, 40)
  81.         Me.btnAbort.TabIndex = 1
  82.         Me.btnAbort.Text = "Abort method"
  83.         '
  84.         'lblMessage
  85.         '
  86.         Me.lblMessage.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
  87.         Me.lblMessage.Location = New System.Drawing.Point(296, 24)
  88.         Me.lblMessage.Name = "lblMessage"
  89.         Me.lblMessage.Size = New System.Drawing.Size(280, 312)
  90.         Me.lblMessage.TabIndex = 2
  91.         '
  92.         'btnAsyncCall
  93.         '
  94.         Me.btnAsyncCall.Location = New System.Drawing.Point(16, 120)
  95.         Me.btnAsyncCall.Name = "btnAsyncCall"
  96.         Me.btnAsyncCall.Size = New System.Drawing.Size(120, 40)
  97.         Me.btnAsyncCall.TabIndex = 3
  98.         Me.btnAsyncCall.Text = "Asynchronous Call"
  99.         '
  100.         'btnTimeout
  101.         '
  102.         Me.btnTimeout.Location = New System.Drawing.Point(16, 24)
  103.         Me.btnTimeout.Name = "btnTimeout"
  104.         Me.btnTimeout.Size = New System.Drawing.Size(120, 40)
  105.         Me.btnTimeout.TabIndex = 4
  106.         Me.btnTimeout.Text = "Test Timeout"
  107.         '
  108.         'btnAsyncMulti
  109.         '
  110.         Me.btnAsyncMulti.Location = New System.Drawing.Point(16, 168)
  111.         Me.btnAsyncMulti.Name = "btnAsyncMulti"
  112.         Me.btnAsyncMulti.Size = New System.Drawing.Size(120, 40)
  113.         Me.btnAsyncMulti.TabIndex = 5
  114.         Me.btnAsyncMulti.Text = "Multiple Async calls"
  115.         '
  116.         'btnPermanentSession
  117.         '
  118.         Me.btnPermanentSession.Location = New System.Drawing.Point(144, 24)
  119.         Me.btnPermanentSession.Name = "btnPermanentSession"
  120.         Me.btnPermanentSession.Size = New System.Drawing.Size(120, 40)
  121.         Me.btnPermanentSession.TabIndex = 6
  122.         Me.btnPermanentSession.Text = "Permanent Sessions"
  123.         '
  124.         'btnCaching
  125.         '
  126.         Me.btnCaching.Location = New System.Drawing.Point(144, 72)
  127.         Me.btnCaching.Name = "btnCaching"
  128.         Me.btnCaching.Size = New System.Drawing.Size(120, 40)
  129.         Me.btnCaching.TabIndex = 7
  130.         Me.btnCaching.Text = "Test Caching"
  131.         '
  132.         'btnException
  133.         '
  134.         Me.btnException.Location = New System.Drawing.Point(144, 120)
  135.         Me.btnException.Name = "btnException"
  136.         Me.btnException.Size = New System.Drawing.Size(120, 40)
  137.         Me.btnException.TabIndex = 8
  138.         Me.btnException.Text = "Test Exception"
  139.         '
  140.         'btnWindowsAuthentication
  141.         '
  142.         Me.btnWindowsAuthentication.Location = New System.Drawing.Point(144, 216)
  143.         Me.btnWindowsAuthentication.Name = "btnWindowsAuthentication"
  144.         Me.btnWindowsAuthentication.Size = New System.Drawing.Size(120, 40)
  145.         Me.btnWindowsAuthentication.TabIndex = 9
  146.         Me.btnWindowsAuthentication.Text = "Windows Authentication"
  147.         '
  148.         'btnSoapHeaders
  149.         '
  150.         Me.btnSoapHeaders.Location = New System.Drawing.Point(144, 168)
  151.         Me.btnSoapHeaders.Name = "btnSoapHeaders"
  152.         Me.btnSoapHeaders.Size = New System.Drawing.Size(120, 40)
  153.         Me.btnSoapHeaders.TabIndex = 10
  154.         Me.btnSoapHeaders.Text = "SOAP Headers"
  155.         '
  156.         'btnCustomAuthentication
  157.         '
  158.         Me.btnCustomAuthentication.Location = New System.Drawing.Point(144, 264)
  159.         Me.btnCustomAuthentication.Name = "btnCustomAuthentication"
  160.         Me.btnCustomAuthentication.Size = New System.Drawing.Size(120, 40)
  161.         Me.btnCustomAuthentication.TabIndex = 11
  162.         Me.btnCustomAuthentication.Text = "Custom authentication"
  163.         '
  164.         'btnOneWay
  165.         '
  166.         Me.btnOneWay.Location = New System.Drawing.Point(16, 216)
  167.         Me.btnOneWay.Name = "btnOneWay"
  168.         Me.btnOneWay.Size = New System.Drawing.Size(120, 40)
  169.         Me.btnOneWay.TabIndex = 12
  170.         Me.btnOneWay.Text = "One-way method calls"
  171.         '
  172.         'btnSoapExtensions
  173.         '
  174.         Me.btnSoapExtensions.Location = New System.Drawing.Point(144, 312)
  175.         Me.btnSoapExtensions.Name = "btnSoapExtensions"
  176.         Me.btnSoapExtensions.Size = New System.Drawing.Size(120, 40)
  177.         Me.btnSoapExtensions.TabIndex = 13
  178.         Me.btnSoapExtensions.Text = "Test Soap Extensions"
  179.         '
  180.         'Form1
  181.         '
  182.         Me.AutoScaleBaseSize = New System.Drawing.Size(7, 17)
  183.         Me.ClientSize = New System.Drawing.Size(600, 357)
  184.         Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnSoapExtensions, Me.btnOneWay, Me.btnCustomAuthentication, Me.btnSoapHeaders, Me.btnWindowsAuthentication, Me.btnException, Me.btnCaching, Me.btnPermanentSession, Me.btnAsyncMulti, Me.btnTimeout, Me.btnAsyncCall, Me.lblMessage, Me.btnAbort, Me.btnTestSession})
  185.         Me.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
  186.         Me.Name = "Form1"
  187.         Me.Text = "Advanced Web Services"
  188.         Me.ResumeLayout(False)
  189.  
  190.     End Sub
  191.  
  192. #End Region
  193.  
  194.     Dim service As New localhost.SampleService()
  195.  
  196.     ' test the Timeout property
  197.  
  198.     Private Sub btnTimeout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTimeout.Click
  199.         Try
  200.             ' Set a timeout of 5 seconds.
  201.             service.Timeout = 5000
  202.             ' Invoke a method that takes 10 seconds to complete.
  203.             service.LengthyMethodCall(10)
  204.         Catch ex As SoapException
  205.             lblMessage.Text = "SOAP Exception: " & ex.message
  206.         Catch ex As WebException
  207.             If ex.Status = WebExceptionStatus.Timeout Then
  208.                 ' The operation timed out.
  209.                 lblMessage.Text = "TIMEOUT: " & ex.message
  210.             Else
  211.                 lblMessage.Text = ex.Message
  212.             End If
  213.         Catch ex As Exception
  214.             ' Another exception has occurred.
  215.             lblMessage.Text = "Exception: " & ex.Message
  216.         End Try
  217.     End Sub
  218.  
  219.     ' test the Abort method - note that you must call the WS from
  220.     ' another thread if you want to abort the call
  221.  
  222.     Private Sub btnAbort_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAbort.Click
  223.         ' run the web service from another thread.
  224.         Dim tr As New Thread(AddressOf CallWebMethod)
  225.         tr.Start()
  226.         ' wait for 5 seconds, then kill the method call.
  227.         Thread.Sleep(5000)
  228.         service.Abort()
  229.     End Sub
  230.  
  231.     ' this proc calls the WS method from another thread
  232.  
  233.     Sub CallWebMethod()
  234.         Try
  235.             ' make a lengthy call
  236.             service.LengthyMethodCall(10)
  237.         Catch ex As WebException
  238.             If ex.Status = WebExceptionStatus.RequestCanceled Then
  239.                 ' the call has been aborted
  240.                 lblMessage.Text = ex.Message
  241.             End If
  242.         End Try
  243.     End Sub
  244.  
  245.     ' test asynchronous WS method calls
  246.  
  247.     Private Sub btnAsyncCall_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAsyncCall.Click
  248.         Dim service As New localhost.SampleService()
  249.         Dim ar As IAsyncResult = service.BeginLengthyMethodCall(2, AddressOf MethodCallback, service)
  250.     End Sub
  251.  
  252.     ' this method is called when the WS method call completes
  253.  
  254.     Sub MethodCallback(ByVal ar As IAsyncResult)
  255.         Dim service As localhost.SampleService = _
  256.             DirectCast(ar.AsyncState, localhost.SampleService)
  257.         service.EndLengthyMethodCall(ar)
  258.         lblMessage.Text = "End of the lengthy method call"
  259.     End Sub
  260.  
  261.     ' call multiple WS methods
  262.  
  263.     Private Sub btnAsyncMulti_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAsyncMulti.Click
  264.         ' Call the web service methods from another thread.
  265.         Dim tr As New Thread(AddressOf CallMultipleWebMethods)
  266.         tr.Start()
  267.     End Sub
  268.  
  269.     ' this proc is where multiple SW methods are called
  270.  
  271.     Sub CallMultipleWebMethods()
  272.         ' run two WS methods asynchronously
  273.         Dim service1 As New localhost.SampleService()
  274.         Dim ar1 As IAsyncResult = service1.BeginLengthyMethodCall(2, Nothing, Nothing)
  275.  
  276.         Dim service2 As New localhost.SampleService()
  277.         Dim ar2 As IAsyncResult = service2.BeginLengthyMethodCall(3, Nothing, Nothing)
  278.  
  279.         lblMessage.Text = "Two method calls have started" & ControlChars.CrLf
  280.         ' wait for 3 seconds.
  281.         Thread.Sleep(3000)
  282.  
  283.         ' set the next constant to True to abort the async method call
  284.         ' if it hasn't completed yet
  285. #Const ABORT_WSMETHODS = False
  286.  
  287. #If ABORT_WSMETHODS Then
  288.         If ar1.IsCompleted Then
  289.             ' if method completed, get the result
  290.             Dim res As Integer = service1.EndLengthyMethodCall(ar1)
  291.         lblMessage.Text &= "First method has been completed" & controlchars.CrLf 
  292.         Else
  293.             ' else, get the WebClientAsyncResult object and call its Abort method
  294.             Dim wcar1 As WebClientAsyncResult = DirectCast(ar1, WebClientAsyncResult)
  295.             wcar1.Abort()
  296.         lblMessage.Text &= "First method has been canceled" & controlchars.CrLf 
  297.         End If
  298.  
  299.         If ar2.IsCompleted Then
  300.         ' if method completed, get the result
  301.             Dim res As Integer = service2.EndLengthyMethodCall(ar2)
  302.         lblMessage.Text  = "Second method call has been completed" & controlchars.CrLf 
  303.         Else
  304.             ' else, get the WebClientAsyncResult object and call its Abort method
  305.             Dim wcar2 As WebClientAsyncResult = CType(ar2, WebClientAsyncResult)
  306.             wcar2.Abort()
  307.         lblMessage.Text &= "Second method call has been canceled" & controlchars.CrLf 
  308.         End If
  309.         ' nothing else to do in this case
  310.         Exit Sub
  311. #End If
  312.  
  313.         ' Wait until both methods complete.
  314.         Dim handleArr() As WaitHandle = {ar1.AsyncWaitHandle, ar2.AsyncWaitHandle}
  315.         WaitHandle.WaitAll(handleArr)
  316.         lblMessage.Text &= "Both methods have been completed"
  317.  
  318.         ' complete the calls
  319.         service1.EndLengthyMethodCall(ar1)
  320.         service2.EndLengthyMethodCall(ar2)
  321.     End Sub
  322.  
  323.     ' test how you can have Session-based web services
  324.     ' each time you click on this button the displayed value is incremented
  325.  
  326.     Private Sub btnTestSession_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTestSession.Click
  327.         ' make the proxy class a cookie container
  328.         If service.CookieContainer Is Nothing Then
  329.             service.CookieContainer = New CookieContainer()
  330.         End If
  331.         ' prove that each call increments this counter
  332.         lblMessage.Text = service.IncrementCounter()
  333.     End Sub
  334.  
  335.     ' test one-way WS calls
  336.  
  337.     Private Sub btnOneWay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOneWay.Click
  338.         ' call a one-way method call.
  339.         Dim service As New localhost.SampleService()
  340.         lblMessage.Text = ""
  341.         ' call the One-way method, no need to complete the call
  342.         service.OneWayLengthyMethodCall(10)
  343.         lblMessage.Text = "Method call started"
  344.     End Sub
  345.  
  346.     ' this proc demonstrates that clients can share a WS state if
  347.     ' they share the same session cookie
  348.  
  349.     Dim saveCookie As Cookie
  350.  
  351.     Private Sub btnPermanentSession_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPermanentSession.Click
  352.         ' make the proxy object a cookie container
  353.         Dim service As New localhost.SampleService()
  354.         service.CookieContainer = New CookieContainer()
  355.  
  356.         ' If we already know the cookie, let's add it to the cookies collection.
  357.         If Not (saveCookie Is Nothing) Then
  358.             service.CookieContainer.Add(saveCookie)
  359.         End If
  360.  
  361.         ' Call the Web Service method.
  362.         lblMessage.Text = service.IncrementCounter()
  363.  
  364.         ' Save the cookie if this is the first call.
  365.         If saveCookie Is Nothing Then
  366.             Dim cookieUri As New Uri("http://localhost")
  367.             ' Get the ASP.NET_SessionID cookie belonging to the localhost URI.
  368.             saveCookie = service.CookieContainer.GetCookies(cookieUri).Item("ASP.NET_SessionId")
  369.         End If
  370.     End Sub
  371.  
  372.     ' test cached WS calls
  373.     ' By clicking on this button multiple times, you'll see that the
  374.     ' time returned doesn't change at each call, because the WS result
  375.     ' is cached
  376.  
  377.     Private Sub btnCaching_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCaching.Click
  378.         Dim service As New localhost.SampleService()
  379.         lblMessage.Text = service.GetTime(1)
  380.         lblMessage.Text &= "  " & service.GetTimeCounter.ToString
  381.     End Sub
  382.  
  383.     ' call a WS method that returns an exception
  384.  
  385.     Private Sub btnException_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnException.Click
  386.         Try
  387.             ' this call throws an exception
  388.             Dim service As New localhost.SampleService()
  389.             service.ThrowAnException()
  390.  
  391.         Catch ex As SoapException When ex.Code.Equals(SoapException.VersionMismatchFaultCode)
  392.  
  393.         Catch ex As SoapException When ex.Code.Equals(SoapException.ServerFaultCode)
  394.             lblMessage.Text = "SOAP Exception: " & ex.Message
  395.  
  396.         Catch ex As SoapException When GetWSException(ex) = "System.NullReferenceException"
  397.             ' get details from the OuterXml property
  398.             lblMessage.Text = ex.Detail.OuterXml
  399.         End Try
  400.     End Sub
  401.  
  402.     ' A reusable routine that extracts the name of the "inner" exception.
  403.  
  404.     Function GetWSException(ByVal ex As SoapException) As String
  405.         ' parse the exception's Message property.
  406.         Dim mc As MatchCollection = Regex.Matches(ex.Message, "---> ([^:]+):")
  407.         If mc.Count >= 1 Then
  408.             ' we've found a match - the first ground contains the value.
  409.             Return mc.Item(0).Groups(1).Value
  410.         End If
  411.     End Function
  412.  
  413.     ' this procedure shows how you can make a WS method call
  414.     ' and impersonate a given Windows account
  415.  
  416.     ' NOTE: you need to edit web.config to enforce Windows authentication
  417.  
  418.     Private Sub btnWindowsAuthentication_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWindowsAuthentication.Click
  419.         ' create network credentials.
  420.         Dim winCred As New NetworkCredential()
  421.         winCred.UserName = "Administrator"
  422.         winCred.Password = "fbxx"
  423.         ' invoke a method, passing the user credentials.
  424.         Dim service As New localhost.SampleService()
  425.         service.Credentials = winCred
  426.         service.LengthyMethodCall(0)
  427.     End Sub
  428.  
  429.     ' this proc tests passing a SOAP header to the WS method
  430.  
  431.     Private Sub btnSoapHeaders_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSoapHeaders.Click
  432.         ' create a SOAP header
  433.         Dim userInfo As New localhost.UserInfoHeader()
  434.         userInfo.Culture = "it-it"
  435.         userInfo.TimeOffset = 1
  436.         ' assign the SOAP header to the proper property in the proxy object
  437.         Dim service As New localhost.SampleService()
  438.         service.UserInfoHeaderValue = userInfo
  439.         ' call the remote method
  440.         lblMessage.Text = service.GetClientTime
  441.     End Sub
  442.  
  443.     ' this procedure shows how you can set up a custom authentication
  444.     ' mechanism based on SOAP headers
  445.  
  446.     Private Sub btnCustomAuthentication_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCustomAuthentication.Click
  447.         ' create a SOAP header
  448.         Dim accountInfo As New localhost.AccountInfoHeader()
  449.         accountInfo.UserName = "JoeDoe"
  450.         accountInfo.Password = "jdpwd"
  451.  
  452.         Try
  453.             ' associate account info with the proxy object.
  454.             Dim service As New localhost.SampleService()
  455.             service.AccountInfoHeaderValue = accountInfo
  456.             ' This call will succeed.
  457.             Dim res As Boolean = service.ProtectedMethod()
  458.             ' this one will fail
  459.             res = service.AnotherProtectedMethod
  460.  
  461.         Catch ex As Exception
  462.             MsgBox(ex.Message, MsgBoxStyle.Critical)
  463.         End Try
  464.     End Sub
  465.  
  466.     ' this proc tests SOAP extensions
  467.  
  468.     Private Sub btnSoapExtensions_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSoapExtensions.Click
  469.         ' prepare a SOAP header with user info
  470.         Try
  471.             ' create a SOAP header that identifies a user with higher privileges
  472.             Dim accountInfo As New localhost.AccountInfoHeader()
  473.             accountInfo.UserName = "AnnSmith"
  474.             accountInfo.Password = "aspwd"
  475.             ' associate account info with the proxy object.
  476.             Dim service As New localhost.SampleService()
  477.             service.AccountInfoHeaderValue = accountInfo
  478.  
  479.             ' This call will succeed.
  480.             lblMessage.Text = "FIRST CALL " & ControlChars.CrLf
  481.             Dim res As Boolean = service.YetAnotherProtectedMethod()
  482.             lblMessage.Text &= res.ToString & ControlChars.CrLf & ControlChars.CrLf
  483.  
  484.             ' now repeat the call with the identity of a user with
  485.             ' fewer privileges
  486.             accountInfo.UserName = "JoeDoe"
  487.             accountInfo.Password = "jdpwd"
  488.             lblMessage.Text &= "SECOND CALL " & ControlChars.CrLf
  489.             ' this call will fail
  490.             res = service.YetAnotherProtectedMethod()
  491.  
  492.         Catch ex As Exception
  493.             lblMessage.Text &= ex.Message
  494.         End Try
  495.     End Sub
  496. End Class
  497.